<%--
  Created by IntelliJ IDEA.
  User: LJJ
  Date: 2023/3/20
  Time: 19:50
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<script src="js/jquery1.42.min.js"></script>
电话：<input type="text" id="phone"><br>
邮箱：<input type="email" id="email">
<button onclick="send()">请求验证码</button>
<br>
验证码：<input type="text" id="yanzheng"><br>
新密码：<input type="password" id="newPassword"><br>
确认新密码：<input type="password" id="rePassword"><br>
<button onclick="test()">确认</button>
<script>


    function send() {
        $.ajax({
            url: "checkEmail.do",
            type: "POST",
            data: {
                "email": $("#email").val(),
                "phone": $("#phone").val()
            },
            dataType: "json",
            success: function (data) {

                if (data) {
                    $.ajax({
                        url: "../send.do",
                        type: "POST",
                        data: {
                            "userEmail": $("#email").val()
                        },
                        dataType: "json",
                        success: function (data) {
                            alert("验证码已发送")
                        }
                    })
                } else {
                    alert("信息有误")
                }
            }
        })


    }


    function test() {

        var password = $("#newPassword").val()
        var rePassword = $("#rePassword").val()

        if (password == rePassword) {
            $.ajax({
                url: "getPassword.do",
                type: "POST",
                data: {
                    "yanzheng": $("#yanzheng").val(),
                    "phone": $("#phone").val(),
                    "password": password

                },
                dataType: "text",
                success: function (data) {
                    if (data == 0) {
                        alert("验证码错误")
                    } else if (data == 2) {
                        alert("失败")
                    } else {
                        alert("成功")
                        window.location.href = "login.jsp"
                    }
                }
            })
        } else {
            alert("请保证两次密码相同")
        }


    }
</script>

</body>
</html>
